﻿using SinavSistemi.Class;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SinavSistemi
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["pid"]!= null)
            {
                txtKullaniciAdi.Text = Request.QueryString["pid"];
                txtParola.Text = "usaegitim";
                txtParola.Visible = false;
            }
        }

        protected void btnGiris_Click(object sender, EventArgs e)
        {
            SqlConnection sqlcon = connection.baglanti;
            SqlCommand sqlcmd = new SqlCommand("select * from kullanicilar where username=@username and password=@password and durum=0",sqlcon);
            sqlcmd.Parameters.AddWithValue("@username",txtKullaniciAdi.Text);
            sqlcmd.Parameters.AddWithValue("@password",txtParola.Text);

            sqlcon.Open();
            SqlDataReader sdr = sqlcmd.ExecuteReader();
            if (sdr.Read())
            {
                Session["userID"] = sdr["userID"].ToString();
                Session["username"] = sdr["adsoyad"].ToString();
                Response.Redirect("panel.aspx");
            }
            else
            {
                hd1.Value = "Yanliş Kullanıcı Adı veya Parola";
            }

            sqlcon.Close();

        }
    }
}